const { router } = require("../../koa/koa-main");
const { uploadImage, getImageURL } = require("../../services/book");

router.post('/uploadImage', async (ctx, next) => {
  const { data } = await uploadImage(ctx.request.body)
  // 上传成功，获取下载地址
  const imgUploadData = JSON.parse(data.resp_data)
  if (imgUploadData.statusCode === -1) {
    const imgDownloadData = await getImageURL({
      fileid: imgUploadData.fileID,
      access_token: ctx.request.body.access_token
    })
    ctx.response.body = imgDownloadData.data
  } else {
    ctx.response.body = data
  }
  await next()
})
